﻿
Public Class operateById
    Public Const functionName As String = "opid"

    Private Shared Sub normalizeOperOverride(ByVal oper As String, ByRef operOverride As String)
        If isemptystring(operOverride) Then
            operOverride = oper
        End If
    End Sub

    Public Shared Sub register(ByVal inlineScript As inlineScript, ByVal oper As String, _
                               Optional ByVal operOverride As String = Nothing)
        'for ajax call
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        normalizeOperOverride(oper, operOverride)
        inlineScript.addscript(network.http.contentType.textjavascript, "operatorById_" + oper _
                               , "function " + functionName + "_" + operOverride + "(i,p)" _
                               + "{" + _
                               operate.invoke(inlineScript, oper, _
                                              getElementById.invoke(inlineScript, "i"), "p", , _
                                              operOverride) + _
                               ";}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal oper As String, _
                                  ByVal id As String, ByVal para As String, _
                                  Optional ByRef actionTarget As String = Nothing, _
                                  Optional ByVal operOverride As String = Nothing) As String
        assert(Not isemptystring(id), "id is an empty string.")
        assert(Not isemptystring(oper), "oper is an empty string.")
        assert(Not isemptystring(para), "para is an empty string.")
        normalizeOperOverride(oper, operOverride)
        If Not inlineScript Is Nothing Then
            register(inlineScript, oper, operOverride)
        End If
        actionTarget += functionName + "_" + operOverride + "(" + id + "," + para + ")"

        Return actionTarget
    End Function
End Class

Public Class disableById
    Public Const oper As String = "disabled"
    Public Const operOverride As String = "dis"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        operateById.register(inlineScript, oper, operOverride)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        Return operateById.invoke(inlineScript, "disabled", id, "true", actionTarget, "dis")
    End Function
End Class

Public Class changeInnerHtmlById
    Public Const oper As String = "innerHTML"
    Public Const operOverride As String = "ih"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        operateById.register(inlineScript, oper, operOverride)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, ByVal value As Object, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        Return operateById.invoke(inlineScript, oper, id, Convert.ToString(value), actionTarget, operOverride)
    End Function
End Class

Public Class changeInnerHtmlAndDisableById
    Public Shared Sub register(ByVal inlineScript As inlineScript)
        disableById.register(inlineScript)
        changeInnerHtmlById.register(inlineScript)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, ByVal value As Object, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        disableById.invoke(inlineScript, id, actionTarget)
        actionTarget += ";"
        Return changeInnerHtmlById.invoke(inlineScript, id, value, actionTarget)
    End Function
End Class

Public Class changeValueById
    Public Const oper As String = changeValue.oper
    Public Const operOverride As String = changeValue.operOverride

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        operateById.register(inlineScript, oper, operOverride)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, ByVal value As Object, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        Return operateById.invoke(inlineScript, oper, id, Convert.ToString(value), actionTarget, operOverride)
    End Function
End Class

Public Class visibilityById
    Public Shared Sub register(ByVal inlineScript As inlineScript)
        visibility.register(inlineScript)
        getElementById.register(inlineScript)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  ByVal display As Boolean, Optional ByRef actionTarget As String = Nothing) As String
        Return visibility.invoke(inlineScript, getElementById.invoke(inlineScript, id), display, actionTarget)
    End Function

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  ByVal value As String, Optional ByRef actionTarget As String = Nothing) As String
        Return visibility.invoke(inlineScript, getElementById.invoke(inlineScript, id), value, actionTarget)
    End Function
End Class

Public Class hideById
    Public Shared Sub register(ByVal inlineScript As inlineScript)
        'assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        visibilityById.register(inlineScript)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        Return visibilityById.invoke(inlineScript, id, False, actionTarget)
    End Function
End Class

Public Class showById
    Public Shared Sub register(ByVal inlineScript As inlineScript)
        'assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        visibilityById.register(inlineScript)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        Return visibilityById.invoke(inlineScript, id, True, actionTarget)
    End Function
End Class

Public Class displayById
    Public Shared Sub register(ByVal inlineScript As inlineScript)
        display.register(inlineScript)
        getElementById.register(inlineScript)
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  ByVal displayStyle As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        Return display.invoke(inlineScript, getElementById.invoke(inlineScript, id), displayStyle, actionTarget)
    End Function
End Class

Public Class zindexById
    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  ByVal zindex As Int64, Optional ByRef actionTarget As String = Nothing) As String
        Return operateById.invoke(inlineScript, "style.zIndex", id, Convert.ToString(zindex), actionTarget, "zi")
    End Function
End Class

Public Class zindexIncreaseById
    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  ByVal zindex As Int64, Optional ByRef actionTarget As String = Nothing) As String
        Return operateById.invoke(inlineScript, "style.zIndex+", id, Convert.ToString(zindex), actionTarget, "zii")
    End Function
End Class
